<template>
  <a-modal
    :title="title"
    :width="modalWidth"
    :visible="visible"
    :confirmLoading="confirmLoading"
    @cancel="close"
  >
    <a-spin :spinning="confirmLoading" style="padding: 0 20px;">
      <a-row>
        <a-col :span="24" style="margin-bottom:15px;" v-if="warnInfo.goodsStockStatus==1">{{$t('您有部分商品已经')}}<span style="color:red;">{{$t('低于库存预警值')}}</span><a style="margin-left:20px;" @click="goLink('/goodsbusiness/InventoryAlertList')">{{$t('前往处理')}}</a></a-col>
        
        <a-col :span="24" style="margin-bottom:15px;" v-if="warnInfo.buyOrder>0">
          <i18n path="warn-note" tag="span">
            <a place="number" style="font-weight: 600">{{ warnInfo.buyOrder }}</a>
            <span place="type" style="color:red;">{{$t('采购单')}}</span>
          </i18n>
          <a style="margin-left:20px;" @click="goLink('/goodsbusiness/GoodsInstockList')">{{$t('前往处理')}}</a>
        </a-col>
        <a-col :span="24" style="margin-bottom:15px;" v-if="warnInfo.inOrder>0">
          <i18n path="warn-note" tag="span">
            <a place="number" style="font-weight: 600">{{ warnInfo.inOrder }}</a>
            <span place="type" style="color:red;">{{$t('入库单')}}</span>
          </i18n>
          <a style="margin-left:20px;" @click="goLink('/goodsbusiness/OtherInOfStore')">{{$t('前往处理')}}</a>
        </a-col>
        <a-col :span="24" style="margin-bottom:15px;" v-if="warnInfo.allotOrder>0">
          <i18n path="warn-note" tag="span">
            <a place="number" style="font-weight: 600">{{ warnInfo.allotOrder }}</a>
            <span place="type" style="color:red;">{{$t('调拨单')}}</span>
          </i18n>
          <a style="margin-left:20px;" @click="goLink('/goodsbusiness/SalesAllotList')">{{$t('前往处理')}}</a>
        </a-col>
        <a-col :span="24" style="margin-bottom:15px;" v-if="warnInfo.lossOrder>0">
          <i18n path="warn-note" tag="span">
            <a place="number" style="font-weight: 600">{{ warnInfo.lossOrder }}</a>
            <span place="type" style="color:red;">{{$t('其他出库单')}}</span>
          </i18n>
          <a style="margin-left:20px;" @click="goLink('/goodsbusiness/OtherOutOfStore')">{{$t('前往处理')}}</a>
        </a-col>
        <a-col :span="24" style="margin-bottom:15px;" v-if="warnInfo.backOrder>0">
          <i18n path="warn-note" tag="span">
            <a place="number" style="font-weight: 600">{{ warnInfo.backOrder }}</a>
            <span place="type" style="color:red;">{{$t('返货单')}}</span>
          </i18n>
          <a style="margin-left:20px;" @click="goLink('/goodsbusiness/ReturnGoodsList')">{{$t('前往处理')}}</a>
        </a-col>
        
        <a-col :span="24" style="margin-bottom:15px;" v-if="warnInfo.giftBalance!=undefined">
          <i18n path="warn-gift" tag="span">
            <span place="balance" style="color:red;">{{ warnInfo.giftBalance }}</span>
          </i18n>
          <a style="margin-left:20px;" @click="goLink('/gift/settings/StoredValueAccount')">{{$t('去充值')}}</a>
        </a-col>
        <a-col :span="24" style="margin-bottom:15px;" v-if="warnInfo.systemValid">
          <i18n path="server-expiration-reminder" tag="div">
            <span place="date" style="color:red;">{{ warnInfo.systemValid }}</span>
          </i18n>
        </a-col>
        <a-col :span="24" v-if="warnInfo.systemValid==undefined&&warnInfo.giftBalance==undefined&&warnInfo.goodsStockStatus==0&&warnInfo.buyOrder==0&&warnInfo.inOrder==0&&warnInfo.lossOrder==0&&warnInfo.allotOrder==0&&warnInfo.backOrder==0" style="margin:15px;font-weight:bold;text-align:center;">{{$t('暂无预警信息')}}</a-col>
        
        <a-col :span="24" style="margin-bottom:15px;" v-if="warnInfo.outUser != null && warnInfo.outUser.length > 0">
          <i18n path="out-user-reminder" tag="span">
            <span place="user" style="color:red;">
              {{warnInfo.outUser.map(post => post.username).join(', ')}}
            </span>
          </i18n>
          <a style="margin-left:20px;" @click="goLink('/isystem/user')">{{$t('前往处理')}}</a>
        </a-col>
        <a-col :span="24" style="margin-bottom:15px;" v-if="warnInfo.outBar != null && warnInfo.outBar.length > 0">
          <i18n path="out-bar-reminder" tag="span">
            <span place="bar" style="color:red;">
              {{warnInfo.outBar.map(post => post.id).join(', ')}}
            </span>
          </i18n>
          <a style="margin-left:20px;" @click="goLink('/terminal/BarManage')">{{$t('前往处理')}}</a>
        </a-col>
        <a-col :span="24" style="margin-bottom:15px;" v-if="warnInfo.lowBar != null && warnInfo.lowBar.length > 0">
          <i18n path="low-bar-reminder" tag="span">
            <span place="bar" style="color:red;">
              {{warnInfo.lowBar.map(post => post.id).join(', ')}}
            </span>
          </i18n>
          <a style="margin-left:20px;" @click="goLink('/terminal/BarManage')">{{$t('前往处理')}}</a>
        </a-col>
        <a-col :span="24" style="margin-bottom:15px;" v-if="warnInfo.barNotice != null && warnInfo.barNotice.length > 0">
          <div style="margin-bottom: 20px" v-for="(item, i) in warnInfo.barNotice" :key="'p' + i">
            <div style="font-weight: 700">
              <span v-if="item.deviceId_dictText">{{ item.deviceId_dictText }}</span>
              <span v-if="item.deviceId">{{ item.deviceId }}</span>
              <span v-if="item.gameId_dictText">{{ item.gameId_dictText }}</span>
              <span v-if="item.machineNo">{{ $t("（") + item.machineNo + $t("）") }}</span>
            </div>
            <div>
              <span style="padding-right: 10px;color:red;">{{ $t("系统服务通知") }}</span>
              <a style="margin-left:20px;" @click="deviceNotice(item)">{{$t('查看详情')}}</a>
            </div>
          </div>
        </a-col>
      </a-row>
    </a-spin>
    <template slot="footer">
      <a-button @click="handleCancel">{{$t('关闭')}}</a-button>
    </template>
    <bis-device-notice-modal ref="noticeModal" @ok="getWarn()"></bis-device-notice-modal>
  </a-modal>
</template>

<script>
  import { getAction } from '@/api/manage'
  import BisDeviceNoticeModal from '@/views/terminal/modules/BisDeviceNoticeModal'
  export default {
    name: "WarnModal",
    components: {
      BisDeviceNoticeModal,
    },
    data () {
      return {
        title:this.$t('消息通知'),
        modalWidth:600,
        visible: false,
        confirmLoading: false,
        warnInfo:{}
      }
    },
    methods: {
      show(){        
        this.visible = true;
        this.getWarn();
      },
      handleCancel () {
        this.close()
      },
      close () {
        this.$emit('close');
        this.visible = false;
      },
      getWarn(){
        getAction('/report/home/systemWarning').then(res=>{
          if(res.success){
            this.warnInfo=res.result;
          }else{
            this.$message.error(res.message)
          }
        })
      },
      goLink(url){
        this.handleCancel()
        this.$router.push(url)
      },
      deviceNotice(record) {
        this.$refs.noticeModal.edit(record)
      }
    }
  }
</script>

<style scoped>

</style>

